#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long LL;

void solve()
{
    LL n, d; cin >> n >> d;
    LL v = 123456789;
    v = v * 10 + d;
    LL p = 0, tmp = n;
    while(tmp)
    {
        p++;
        tmp /= 10;
    }
    v = v * pow(10, p);
    p = v % n;
    cout << (v + n - p) / n << endl; 
}

int main()
{
    int T; cin >> T;
    while(T--)
    {
        solve();
    }
    return 0;
}